<?php
	class BowenClass{
		function __construct(){

			@$bb=$_GET['func'];
				if($bb =="delete"){
					$this->delete();
				}elseif($bb =="modify"){
					$this->modify();
				}elseif($bb =="query"){
					$this->query();
				}elseif($bb =='home_page'){
					$this->home_page();
				}
				elseif($bb =='mess'){
					$this->mess();
				}else{
					$this->Bowen();
				}
		}
		
		function mess(){
			
			$page_size=3;
			$sql2=mysql_query("SELECT count(id) FROM test_papapa");
			$rel2=mysql_fetch_row($sql2);
			$total=$rel2[0];
			$page_max=ceil($total/$page_size);
	        if(!isset($_GET["page_num"]) || $_GET['page_num']>$page_max || $_GET['page_num']<1) {
	       	    $page_num=1;
	        }else{
	       	    $page_num=$_GET["page_num"];
	        }
		    $front=($page_num-1)*$page_size;
			$sql=mysql_query("select * from test_papapa limit $front,$page_size");							
			$rel=mysql_fetch_object($sql);
     		require_once('./Bowen.php');
 
		}
		
			function delete(){
				$id=$_GET['id'];
				$sql="delete from test_papapa where id='$id'";
				$r=mysql_query($sql);
				if($r){
					echo "<script>alert('删除成功');window.location.href='./index.php?action=BowenClass&func=Bowen';</script>";
				}else{
					echo "<script>alert('删除失败');history.back();</script>";
				}
				require_once('./Bowen.php');
			}

        function query(){
        	$keywords=$_POST['keywords'];
			$page_size=7;
			$sql2=mysql_query("SELECT count(id) FROM test_papapa");
			$rel2=mysql_fetch_row($sql2);
			$total=$rel2[0];
			$page_max=ceil($total/$page_size);
	        if(!isset($_GET["page_num"]) || $_GET['page_num']>$page_max || $_GET['page_num']<1) {
	       	    $page_num=1;
	        }else{
	       	    $page_num=$_GET["page_num"];
	        }
		    $front=($page_num-1)*$page_size;
			$sql=mysql_query("select * from test_papapa where   name like '%$keywords%'  or  id like '%$keywords%'  or title like '%$keywords%'  or picture like '%$keywords%' limit $front,$page_size");							
				 if($keywords==""){
		    	echo "<script>alert('查找的内容不能为空');</script>";
		    }
			$rel=mysql_fetch_object($sql);
     		 require_once('./Bowen.php');
        }
        
		function home_page(){
		
			
			require_once('./index_2.php  ');
		}
        
        
        function Bowen(){
        	$page_size=3;
			$sql2=mysql_query("SELECT count(id) FROM test_papapa");
			$rel2=mysql_fetch_row($sql2);
			$total=$rel2[0];
			$page_max=ceil($total/$page_size);
	        if(!isset($_GET["page_num"]) || $_GET['page_num']>$page_max || $_GET['page_num']<1) {
	       	    $page_num=1;
	        }else{
	       	    $page_num=$_GET["page_num"];
	        }
		    $front=($page_num-1)*$page_size;
			$sql=mysql_query("select * from test_papapa limit $front,$page_size");							
			$rel=mysql_fetch_object($sql);
     		require_once('./Bowen.php');
        }
	}
	
	?>